package com.spring.propertyioc;

import java.beans.PropertyEditorSupport;

public class CustomerCarEditor extends PropertyEditorSupport {

    //将字面值转换为属性类型对象
    @Override
    public void setAsText(String text) throws IllegalArgumentException {
        if(null == text || text.indexOf(",") == -1){
            throw new IllegalArgumentException("设置的字符串格式不正确");
        }
        String[] infos = text.split(",");
        Car car = new Car();
        car.setMaxSpeed(Integer.parseInt(infos[0]));
        car.setName(infos[1]);
        car.setPrice(Double.parseDouble(infos[2]));

        //调用父类的setValue方法设置转换后的属性对象
        setValue(car);
    }
}
